﻿using FindLatestFile.Models;

namespace CgdataBase;

public class AppSettings : AppSettingsBase, IAppSettings
{
    public FileInfoEx[]? FileItems { get; set; }
    public bool DeleteToRecycleBin { get; set; } = true;
    public bool OrderByDescending { get; set; }
    public bool ShowAllFiles { get; set; }
    public OrderType Order { get; set; }

    public override void LoadConfig()
    {
        try
        {
            if (File.Exists(_path))
            {
                var cfg = XmlEngine.Load<AppSettings>(_path);
                ObjectHelper.DeepCopy(cfg, this);
            }
        }
        catch (Exception ex)
        {
            _logger.Error(ex);
        }
        SaveConfig();
    }

    public override void SaveConfig()
    {
        try
        {
            XmlEngine.Save(_path, this);
        }
        catch (Exception ex)
        {
            _logger.Error(ex);
        }
    }
}

public interface IAppSettings : IAppSettingsBase
{
    public FileInfoEx[]? FileItems { get; set; }
    public bool DeleteToRecycleBin { get; set; } 
    public bool OrderByDescending { get; set; }
    public OrderType Order { get; set; }
    public bool ShowAllFiles { get; set; }
}